#include<bits/stdc++.h>
#define int long long
using namespace std;
inline void chmax(int &x,int y){if(y>x)x=y;}
main(){
  freopen("kte.in","r",stdin);
  freopen("kte.out","w",stdout);
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int q; cin>>q;
  if(q<=3e4){
    vector<int> s;
    while(q--){
      int x,c=0,l=0,c1=0,c2=0; cin>>x;
      auto p=lower_bound(s.begin(),s.end(),x);
      if(p!=s.end()&&*p==x)s.erase(p);
      else s.insert(p,x);
      for(int i=0,j=s.size()-1;i<s.size();i++,j--,l=c2)
        chmax(l,c1+=s[i]),c+=(c2+=s[j])-l;
      cout<<c<<'\n';
    }
  }
  else{
    set<int> s; int sm=0;
    while(q--){
      int x; cin>>x;
      if(s.find(x)==s.end())s.emplace(x),sm+=x;
      else s.erase(x),sm-=x;
      if(s.size()<=5000||x==*s.begin()||x==*prev(s.end())){
        vector<int> v(s.begin(),s.end());
        int c=0,l=0,c1=0,c2=0;
        for(int i=0,j=v.size()-1;i<v.size();i++,j--,l=c2)
          chmax(l,c1+=v[i]),c+=(c2+=v[j])-l;
        cout<<(sm=c)<<'\n';
      }
      else cout<<sm<<'\n';
    }
  }
  return 0;
}